/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package introsemp;

import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author Marit
 */
public class SubjectUI {
    JDialog dbox = new JDialog();
    JLabel subjectLabel = new JLabel("Subject:");
    JCheckBox othersBox = new JCheckBox("Others:");
    JLabel unitsLabel = new JLabel("Units:");
    JCheckBox addToAllBox = new JCheckBox("Add this to all <year> sections");
    
    JComboBox subjectList = new JComboBox();
    JTextField othersField = new JTextField();
    JTextField unitsField = new JTextField();
    JButton ok = new JButton("OK");
    JButton cancel = new JButton("Cancel");
    /****** FOR TESTING ******/
    public static void main (String args[]) {
        SubjectUI subjectui = new SubjectUI();
        subjectui.addSubject();
    }
    
    public void addSubject(){
        dialogBoxLoader();
    }
    
    public void dialogBoxLoader(){
        dbox.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        dbox.setSize(400,400);
        dbox.setLayout(null);
        dbox.setBackground(Color.white);
        /*
        ok.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (itemField.getText().isEmpty()) 
                        JOptionPane.showMessageDialog(dbox,"Please answer all fields\n"+" ", "Error", JOptionPane.ERROR_MESSAGE);
                    
                    else if (intCheck(itemField.getText()))
                        JOptionPane.showMessageDialog(dbox,"Items should only consist of integers\n"+" ", "Invalid Input.", JOptionPane.ERROR_MESSAGE);
                    else {
                        JOptionPane.showMessageDialog(dbox,"<Name of activity> has been succesfully added.\n"+" ");
                        close();
                    }
                }
        });
        cancel.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    close();
                }
        });
        */
        subjectLabel.setSize(58, 16);
        subjectLabel.setLocation(70, 80);
        subjectLabel.setVisible(true);
        
        subjectList.setSize(150, 26);
        subjectList.setLocation(135, 80);
        subjectList.setVisible(true);
        
        othersBox.setSize(70, 16);
        othersBox.setLocation(50, 125);
        othersBox.setVisible(true);
        
        othersField.setSize(150, 26);
        othersField.setLocation(135, 120);
        othersField.setVisible(true);
        
        unitsLabel.setSize(58, 16);
        unitsLabel.setLocation(80, 165);
        unitsLabel.setVisible(true);
        
        unitsField.setSize(150, 26);
        unitsField.setLocation(135, 160);
        unitsField.setVisible(true);
        
        addToAllBox.setSize(250, 26);
        addToAllBox.setLocation(100, 200);
        addToAllBox.setVisible(true);
        
        
        ok.setSize(70, 25);
        ok.setLocation(135, 240);
        ok.setVisible(true);
        
        cancel.setSize(75, 25);
        cancel.setLocation(210, 240);
        cancel.setVisible(true);
        
        dbox.add(ok);
        dbox.add(cancel);
        dbox.add(subjectLabel);
        dbox.add(othersBox);
        dbox.add(unitsLabel);
        dbox.add(subjectList);
        dbox.add(othersField);
        dbox.add(unitsField);
        dbox.add(addToAllBox);
        dbox.setVisible(true);
    }
    
    public void close(){
        dbox.dispose();
    }
    
    public boolean intCheck(String what) {
        boolean tf = false;
        for (int i = 0; what.length()>i; i++) {
            for (char j='A'; 'z'>j; j++) {
                if (what.charAt(i)==j)
                tf = true;
            }
        }
        return tf;
    }
}
